{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.11-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python361164bitpytrochcondae51393cc87754f83a49faf18fa04379a",
   "display_name": "Python 3.6.11 64-bit ('pytroch': conda)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "feature = ['kys','value',\"idTransPrinter\",\"desTransPrinter\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# curaEngine文件\n",
    "ce_global_file = \"./CuraEngine/ce_global_setting_e0_t3.csv\"\n",
    "ce_extrude_file = \"./CuraEngine/ce_extruder_setting_e0_t3.csv\"\n",
    "# cura文件\n",
    "c_global_file = './Cura/2-添加了说明信息的全局配置2.xlsx'\n",
    "c_exrude_file = \"./Cura/2-添加了说明信息的挤出机配置2.xlsx\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "quality_cfg = './cfg/Cura中的打印设置.xlsx'\n",
    "df_quality_cfg = pd.read_excel(quality_cfg)\n",
    "feature2 = ['kys','label_type']\n",
    "df_quality_cfg  = df_quality_cfg[feature2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_ce_global = pd.read_csv(ce_global_file)\n",
    "df_c_global = pd.read_excel(c_global_file)\n",
    "df_c_global = df_c_global[feature]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_ce_global[\"value2\"] = df_ce_global.apply(lambda row : row[1].replace(\"\\\"\",\"\"),axis=1)\n",
    "df_c_global[\"value\"] = df_c_global.apply(lambda row : row[1].replace(\"\\\"\",\"\"),axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 合并两张表\n",
    "df_global_all = pd.merge(df_c_global,df_ce_global,on='kys',how='outer')\n",
    "df_global_all[\"flag\"] = df_global_all['value'] == df_global_all['value2']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "(587, 6)"
      ]
     },
     "metadata": {},
     "execution_count": 7
    }
   ],
   "source": [
    "df_global_all.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_global_all = pd.merge(df_global_all,df_quality_cfg,on='kys',how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "(587, 7)"
      ]
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "source": [
    "df_global_all.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_global_all.to_excel(\"3-cura与curaEngine的参数比较2_e0_t3.xlsx\",index=False)"
   ]
  },
  {
   "source": [
    "### 现在比较挤出机设置"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_ce_exrude = pd.read_csv(ce_extrude_file)\n",
    "df_c_exrude= pd.read_excel(c_exrude_file)\n",
    "df_c_exrude = df_c_exrude[feature]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_ce_exrude[\"value2\"] = df_ce_exrude.apply(lambda row : row[1].replace(\"\\\"\",\"\"),axis=1)\n",
    "df_c_exrude[\"value\"] = df_c_exrude.apply(lambda row : row[1].replace(\"\\\"\",\"\"),axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 合并两张表\n",
    "df_extrude_all = pd.merge(df_ce_exrude,df_c_exrude,on='kys',how='outer')\n",
    "df_extrude_all[\"flag\"] = df_extrude_all['value'] == df_extrude_all['value2']\n",
    "df_extrude_all = pd.merge(df_extrude_all,df_quality_cfg,on='kys',how='left')\n",
    "df_extrude_all.to_excel(\"3-cura与curaEngine的参数比较2-挤出机-e0-t3.xlsx\",index=False)"
   ]
  },
  {
   "source": [
    "### 读取txt文件"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "testFile = 'test2.txt'\n",
    "with open(testFile,'r') as f:\n",
    "    lines = f.readlines()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "machine_name DeltacombShiep\n('material_guid', 0)\nmachine_gcode_flavor RepRap(Marlin/Sprinter)\nmachine_head_with_fans_polygon [[-20,10],[10,10],[10,-10],[-20,-10]]\nskin_angles []\ninfill_angles []\nsupport_infill_angles []\nsupport_interface_angles []\nsupport_roof_angles []\nsupport_bottom_angles []\nroofing_angles []\n('cross_infill_density_image', 0)\n('cross_support_density_image', 0)\nmesh_rotation_matrix [[1,0,0],[0,1,0],[0,0,1]]\n"
     ]
    }
   ],
   "source": [
    "data = []\n",
    "for line in lines:\n",
    "    temp_split = line.strip().split(\" \")\n",
    "    if len(temp_split) == 1:\n",
    "        print((temp_split[0],0))\n",
    "        data.append((temp_split[0],-99))\n",
    "    elif len(temp_split) == 2:\n",
    "        data.append((temp_split[0],temp_split[1]))\n",
    "    elif len(temp_split) > 2:\n",
    "        print(temp_split[0],''.join(temp_split[1:]))\n",
    "        data.append((temp_split[0],''.join(temp_split[1:])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_test = pd.DataFrame(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_test.rename(columns={0:\"kys\",1:\"value3\"},inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "                                    kys                     value3\n",
       "0                          machine_name             DeltacombShiep\n",
       "1                 machine_show_variants                      False\n",
       "2                         material_guid                        -99\n",
       "3                     material_diameter                       2.85\n",
       "4                material_bed_temp_wait                       True\n",
       "5              material_print_temp_wait                       True\n",
       "6           material_print_temp_prepend                       True\n",
       "7             material_bed_temp_prepend                       True\n",
       "8                         machine_width                        190\n",
       "9                         machine_depth                        190\n",
       "10                        machine_shape                   elliptic\n",
       "11              machine_buildplate_type                      glass\n",
       "12                       machine_height                        250\n",
       "13                   machine_heated_bed                       True\n",
       "14          machine_heated_build_volume                      False\n",
       "15     machine_always_write_active_tool                      False\n",
       "16               machine_center_is_zero                       True\n",
       "17               machine_extruder_count                          1\n",
       "18              extruders_enabled_count                        1.0\n",
       "19    machine_nozzle_tip_outer_diameter                          1\n",
       "20         machine_nozzle_head_distance                          3\n",
       "21       machine_nozzle_expansion_angle                         45\n",
       "22             machine_heat_zone_length                         16\n",
       "23          machine_nozzle_temp_enabled                       True\n",
       "24         machine_nozzle_heat_up_speed                        2.0\n",
       "25       machine_nozzle_cool_down_speed                        2.0\n",
       "26    machine_min_cool_heat_time_window                       50.0\n",
       "27                 machine_gcode_flavor    RepRap(Marlin/Sprinter)\n",
       "28             machine_firmware_retract                      False\n",
       "29       machine_extruders_share_heater                      False\n",
       "..                                  ...                        ...\n",
       "533               bridge_skin_density_2                         75\n",
       "534                  bridge_fan_speed_2                          0\n",
       "535                 bridge_skin_speed_3                         15\n",
       "536         bridge_skin_material_flow_3                        110\n",
       "537               bridge_skin_density_3                         80\n",
       "538                  bridge_fan_speed_3                          0\n",
       "539                clean_between_layers                      False\n",
       "540           max_extrusion_before_wipe                         10\n",
       "541              wipe_retraction_enable                       True\n",
       "542              wipe_retraction_amount                        3.5\n",
       "543  wipe_retraction_extra_prime_amount                          0\n",
       "544               wipe_retraction_speed                       70.0\n",
       "545       wipe_retraction_retract_speed                          5\n",
       "546         wipe_retraction_prime_speed                          5\n",
       "547                          wipe_pause                          0\n",
       "548                     wipe_hop_enable                        1.0\n",
       "549                     wipe_hop_amount                        0.5\n",
       "550                      wipe_hop_speed                         10\n",
       "551                    wipe_brush_pos_x                        100\n",
       "552                   wipe_repeat_count                          5\n",
       "553                  wipe_move_distance                         20\n",
       "554                 small_hole_max_size                          0\n",
       "555            small_feature_max_length                        0.0\n",
       "556          small_feature_speed_factor                         50\n",
       "557        small_feature_speed_factor_0                         50\n",
       "558                       center_object                      False\n",
       "559                     mesh_position_x                          0\n",
       "560                     mesh_position_y                          0\n",
       "561                     mesh_position_z                          0\n",
       "562                mesh_rotation_matrix  [[1,0,0],[0,1,0],[0,0,1]]\n",
       "\n",
       "[563 rows x 2 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>kys</th>\n      <th>value3</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>machine_name</td>\n      <td>DeltacombShiep</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>machine_show_variants</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>material_guid</td>\n      <td>-99</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>material_diameter</td>\n      <td>2.85</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>material_bed_temp_wait</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>material_print_temp_wait</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>material_print_temp_prepend</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>material_bed_temp_prepend</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>machine_width</td>\n      <td>190</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>machine_depth</td>\n      <td>190</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>machine_shape</td>\n      <td>elliptic</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>machine_buildplate_type</td>\n      <td>glass</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>machine_height</td>\n      <td>250</td>\n    </tr>\n    <tr>\n      <th>13</th>\n      <td>machine_heated_bed</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>machine_heated_build_volume</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>15</th>\n      <td>machine_always_write_active_tool</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>16</th>\n      <td>machine_center_is_zero</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>17</th>\n      <td>machine_extruder_count</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>18</th>\n      <td>extruders_enabled_count</td>\n      <td>1.0</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>machine_nozzle_tip_outer_diameter</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>20</th>\n      <td>machine_nozzle_head_distance</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>21</th>\n      <td>machine_nozzle_expansion_angle</td>\n      <td>45</td>\n    </tr>\n    <tr>\n      <th>22</th>\n      <td>machine_heat_zone_length</td>\n      <td>16</td>\n    </tr>\n    <tr>\n      <th>23</th>\n      <td>machine_nozzle_temp_enabled</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>24</th>\n      <td>machine_nozzle_heat_up_speed</td>\n      <td>2.0</td>\n    </tr>\n    <tr>\n      <th>25</th>\n      <td>machine_nozzle_cool_down_speed</td>\n      <td>2.0</td>\n    </tr>\n    <tr>\n      <th>26</th>\n      <td>machine_min_cool_heat_time_window</td>\n      <td>50.0</td>\n    </tr>\n    <tr>\n      <th>27</th>\n      <td>machine_gcode_flavor</td>\n      <td>RepRap(Marlin/Sprinter)</td>\n    </tr>\n    <tr>\n      <th>28</th>\n      <td>machine_firmware_retract</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>29</th>\n      <td>machine_extruders_share_heater</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>533</th>\n      <td>bridge_skin_density_2</td>\n      <td>75</td>\n    </tr>\n    <tr>\n      <th>534</th>\n      <td>bridge_fan_speed_2</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>535</th>\n      <td>bridge_skin_speed_3</td>\n      <td>15</td>\n    </tr>\n    <tr>\n      <th>536</th>\n      <td>bridge_skin_material_flow_3</td>\n      <td>110</td>\n    </tr>\n    <tr>\n      <th>537</th>\n      <td>bridge_skin_density_3</td>\n      <td>80</td>\n    </tr>\n    <tr>\n      <th>538</th>\n      <td>bridge_fan_speed_3</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>539</th>\n      <td>clean_between_layers</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>540</th>\n      <td>max_extrusion_before_wipe</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>541</th>\n      <td>wipe_retraction_enable</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>542</th>\n      <td>wipe_retraction_amount</td>\n      <td>3.5</td>\n    </tr>\n    <tr>\n      <th>543</th>\n      <td>wipe_retraction_extra_prime_amount</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>544</th>\n      <td>wipe_retraction_speed</td>\n      <td>70.0</td>\n    </tr>\n    <tr>\n      <th>545</th>\n      <td>wipe_retraction_retract_speed</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>546</th>\n      <td>wipe_retraction_prime_speed</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>547</th>\n      <td>wipe_pause</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>548</th>\n      <td>wipe_hop_enable</td>\n      <td>1.0</td>\n    </tr>\n    <tr>\n      <th>549</th>\n      <td>wipe_hop_amount</td>\n      <td>0.5</td>\n    </tr>\n    <tr>\n      <th>550</th>\n      <td>wipe_hop_speed</td>\n      <td>10</td>\n    </tr>\n    <tr>\n      <th>551</th>\n      <td>wipe_brush_pos_x</td>\n      <td>100</td>\n    </tr>\n    <tr>\n      <th>552</th>\n      <td>wipe_repeat_count</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>553</th>\n      <td>wipe_move_distance</td>\n      <td>20</td>\n    </tr>\n    <tr>\n      <th>554</th>\n      <td>small_hole_max_size</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>555</th>\n      <td>small_feature_max_length</td>\n      <td>0.0</td>\n    </tr>\n    <tr>\n      <th>556</th>\n      <td>small_feature_speed_factor</td>\n      <td>50</td>\n    </tr>\n    <tr>\n      <th>557</th>\n      <td>small_feature_speed_factor_0</td>\n      <td>50</td>\n    </tr>\n    <tr>\n      <th>558</th>\n      <td>center_object</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>559</th>\n      <td>mesh_position_x</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>560</th>\n      <td>mesh_position_y</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>561</th>\n      <td>mesh_position_z</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>562</th>\n      <td>mesh_rotation_matrix</td>\n      <td>[[1,0,0],[0,1,0],[0,0,1]]</td>\n    </tr>\n  </tbody>\n</table>\n<p>563 rows × 2 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 42
    }
   ],
   "source": [
    "df_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "                     kys     value idTransPrinter      desTransPrinter value2  \\\n",
       "0    initial_extruder_nr         0            NaN                  NaN    NaN   \n",
       "1                    day       Thu            NaN                  NaN    NaN   \n",
       "2                   time  16:36:27            NaN                  NaN    NaN   \n",
       "3  print_bed_temperature        60            NaN                  NaN    NaN   \n",
       "4    bridge_skin_speed_3      36.0      连桥第三层表面速度   打印桥梁第三层表面时使用的打印速度。     15   \n",
       "\n",
       "    flag label_type  \n",
       "0  False        NaN  \n",
       "1  False        NaN  \n",
       "2  False        NaN  \n",
       "3  False        NaN  \n",
       "4  False        NaN  "
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>kys</th>\n      <th>value</th>\n      <th>idTransPrinter</th>\n      <th>desTransPrinter</th>\n      <th>value2</th>\n      <th>flag</th>\n      <th>label_type</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>initial_extruder_nr</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>day</td>\n      <td>Thu</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>time</td>\n      <td>16:36:27</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>print_bed_temperature</td>\n      <td>60</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>bridge_skin_speed_3</td>\n      <td>36.0</td>\n      <td>连桥第三层表面速度</td>\n      <td>打印桥梁第三层表面时使用的打印速度。</td>\n      <td>15</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 43
    }
   ],
   "source": [
    "df_global_all.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "# df_global_all = pd.merge(df_global_all,df_quality_cfg,on='kys',how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_extend_global_all = pd.merge(df_global_all,df_test,on='kys',how='left')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_extend_global_all[\"flag2\"] = df_extend_global_all['value'] == df_extend_global_all['value3']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_extend_global_all.to_excel(\"4-包含脚本测试数据的对比.xlsx\",index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}